package com.zxc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxc.dao.SctServiceMapper;
import com.zxc.entity.SctService;
import com.zxc.service.SctServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
public class SctServiceServiceImpl extends ServiceImpl<SctServiceMapper, SctService> implements SctServiceService {

    @Autowired
    private SctServiceMapper sctServiceMapper;

    @Override
    @Transactional
    public int saveService(SctService sctService) {
        int result = sctServiceMapper.insert(sctService);
        return result;
    }


    @Override
    @Transactional
    public int delete(Integer[] custNo) {
        return sctServiceMapper.deleteBatchIds(Arrays.asList(custNo));
    }

    @Override
    @Transactional
    public int updateDistributionById(SctService sctService) {
        int result = sctServiceMapper.updateById(sctService);
        return result;
    }

    @Override
    public int selectCountSctServiceBySvrType(String typeName,String searchYear) {
        String searchYears = (Integer.parseInt(searchYear)+1)+"-01-01 00:00:00";
        searchYear = searchYear + "-01-01 00:00:00";
        //返回客户服务表中与服务类型名称相同的记录数
        int count = sctServiceMapper.selectCountSctServiceBySvrType(typeName,searchYear,searchYears);
        return count;
    }

    @Override
    public SctService getSctServiceById(Integer svrId) {
        SctService sctService = sctServiceMapper.selectById(svrId);
        return sctService;
    }

    /*根据服务状态查询*/
    @Override
    public int selectSctServiceCountByStatus(String svrType) {
        QueryWrapper queryWrapper  = new QueryWrapper();
        queryWrapper.eq("svr_status",svrType);
        int total = sctServiceMapper.selectCount(queryWrapper);
        return total;
    }

    @Override
    public List<SctService> getSctServiceListBySvrStatus(int skipCounts, Integer pageSize, String svrType) {
        List<SctService> sctServiceList = sctServiceMapper.selectSctServiceList(skipCounts,pageSize,svrType,null);
        return sctServiceList;
    }
}
